package com.ruoyi.web.controller.procurement;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.procurement.domain.PsUnit;
import com.ruoyi.procurement.service.IPsUnitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库单位Controller
 * 
 * @author ruoyi
 * @date 2023-10-10
 */
@RestController
@RequestMapping("/procurement-system/unit")
public class PsUnitController extends BaseController
{
    @Autowired
    private IPsUnitService psUnitService;

    /**
     * 查询出库单位列表
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:unit:list')")
    @GetMapping("/list")
    public TableDataInfo list(PsUnit psUnit)
    {
        startPage();
        List<PsUnit> list = psUnitService.selectPsUnitList(psUnit);
        return getDataTable(list);
    }

    /**
     * 导出出库单位列表
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:unit:export')")
    @Log(title = "出库单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PsUnit psUnit)
    {
        List<PsUnit> list = psUnitService.selectPsUnitList(psUnit);
        ExcelUtil<PsUnit> util = new ExcelUtil<PsUnit>(PsUnit.class);
        util.exportExcel(response, list, "出库单位数据");
    }

    /**
     * 获取出库单位详细信息
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:unit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(psUnitService.selectPsUnitById(id));
    }

    /**
     * 新增出库单位
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:unit:add')")
    @Log(title = "出库单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PsUnit psUnit)
    {
        return toAjax(psUnitService.insertPsUnit(psUnit));
    }

    /**
     * 修改出库单位
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:unit:edit')")
    @Log(title = "出库单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PsUnit psUnit)
    {
        return toAjax(psUnitService.updatePsUnit(psUnit));
    }

    /**
     * 删除出库单位
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:unit:remove')")
    @Log(title = "出库单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(psUnitService.deletePsUnitByIds(ids));
    }
}
